﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;

public partial class admin_roleEdit : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!Page.IsPostBack)
        {
            getInfo();
        }
    }
    //获取值
    void getInfo(){
        if (Request["id"] != null && Request["id"].ToString().Trim().Length > 0)
        { 
            //获取此角色
            OleDbConnection conn = DB.conn();
            if (conn != null) {
                conn.Open();
                OleDbCommand comm = null;
                try
                {
                    comm = new OleDbCommand();
                    comm.Connection = conn;
                    comm.CommandText = "select * from roles where id=" + Request["id"].ToString().Trim();
                    OleDbDataReader dr = comm.ExecuteReader();
                    if (dr != null && dr.HasRows) {
                        dr.Read();
                        roleName.Text = dr["roleName"].ToString();
                        roleOrder.Text = dr["roleOrder"].ToString();
                    }
                }
                catch (Exception error)
                {
                    Response.Write(error.ToString());
                }
                finally {
                    if(comm!=null)
                        comm.Dispose();
                    conn.Close();
                }
            }
        }
    }
    //提交处理
    public void edit(object sender, EventArgs e)
    {
        string roleName = Request["roleName"].ToString();
        string roleOrder = Request["roleOrder"].ToString();
        try
        {
            if (Request["id"] != null && Request["id"].ToString().Trim().Length > 0)
            {
                //更新
                RoleDao.update(Request["id"].ToString().Trim(), roleName, roleOrder);
            }
            else
            {
                //添加
                RoleDao.add(roleName, roleOrder);
            }
            Response.Write("<script>alert('提交成功！');location.href='role.aspx';</script>");
        }
        catch (Exception error)
        {
            Response.Write(error.ToString());
        }
    }
}
